<?php
/**
 *   Joomdiet - components/views/dietcalibratoritem/view.raw.php
 *   Author: Juan Dapena Paz (juan@bittingbits.com)
 *   Copyright (C) 2010 Bitting Bits S.L.
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
defined('_JEXEC') or die ('Restricted access');
jimport('joomla.application.component.view');

class JoomdietViewDietCalibratorItem extends JView
{
    function display($tpl=null)
    {
        $recipe_model = $this->getModel();
        $recipefood_model = $this->getModel('RecipeFood');
        $food_model = $this->getModel('Food');
        
        $recipe_id = JRequest::getVar('recipeid');
        $amount = JRequest::getVar('amount');
        $itemtype = JRequest::getVar('itemtype');
        
        if (JRequest::getVar('itemtype') == 1) {
        
            $recipe = $recipe_model->getRecipe($recipe_id);
            $ingredient_ids = $recipefood_model->getData($recipe_id);
            
            $ingredients = array();
            foreach ($ingredient_ids as $recipefood) {
                $ingredients[] = $food_model->getFood($recipefood->id_food);
            }
        } else if (JRequest::getVar('itemtype') == 2) {
            $recipe = $food_model->getFood($recipe_id);
            $ingredients = array();
        }
        
        $this->assignRef('recipeid', $recipe_id);
        $this->assignRef('recipe', $recipe);
        $this->assignRef('ingredients', $ingredients);
        $this->assignRef('amounts', $ingredient_ids);
        $this->assignRef('amount', $amount);
        $this->assignRef('itemtype', $itemtype);
        
        parent::display($tpl);
    }
}
?>
